package demo2;

import java.io.IOException;
import java.net.DatagramPacket;
import java.net.DatagramSocket;
import java.net.InetAddress;

public class Demo2 {
    public static void main(String[] args) throws IOException {
        //接受数据
        DatagramSocket ds = new DatagramSocket(10011);
        byte[] bytes = new byte[1024];

        DatagramPacket dp = new DatagramPacket(bytes,bytes.length);;
        ds.receive(dp);

        byte[] data = dp.getData();
        InetAddress address = dp.getAddress();
        int port = dp.getPort();

        System.out.println("端口:" + port);
        System.out.println("地址:" + address);
        System.out.println("内容:" + new String(data,data.length));;



    }
}
